package com.view.jameson.androidrecyclerviewcard;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.LinearSnapHelper;
import androidx.recyclerview.widget.PagerSnapHelper;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.bumptech.glide.Glide;
import com.view.jameson.library.BannerRecyclerView;
import com.view.jameson.library.BannerScaleHelper;

import java.util.ArrayList;
import java.util.List;

public class MainActivity2 extends Activity {

    private CardAdapter mAdapter;
    private List<CardViewBean> mList = new ArrayList<>();

    private RecyclerView mRecyclerView;
    private int mOrderIndex;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
        super.setContentView(R.layout.activity_main2);
        initView();
    }

    private void initView() {
        mRecyclerView = findViewById(R.id.recyclerView);
        ImageView im111 = findViewById(R.id.im111);
        ImageView im222 = findViewById(R.id.im222);
        Glide.with(this)
                .load("https://m.bbmaiqiu.com/api/forehead/system/file/get/65812fed0419d3282052e1ba.jpeg")
//                    .placeholder(R.mipmap.ic_launcher)
                .into(im111);

        Glide.with(this)
                .load("https://m.bbmaiqiu.com/api/forehead/system/file/get/65812fed0419d3282052e1ba.jpeg")
//                    .placeholder(R.mipmap.ic_launcher)
                .into(im222);
        mAdapter = new CardAdapter(mList, this);
        mList.add(new CardViewBean("https://m.bbmaiqiu.com/api/forehead/system/file/get/65812fed0419d3282052e1ba.jpeg"));
        mList.add(new CardViewBean("https://www.wanandroid.com/blogimgs/62c1bd68-b5f3-4a3c-a649-7ca8c7dfabe6.png"));
        mList.add(new CardViewBean("https://www.wanandroid.com/blogimgs/62c1bd68-b5f3-4a3c-a649-7ca8c7dfabe6.png"));
        mAdapter = new CardAdapter(mList, this);
        mRecyclerView.setAdapter(mAdapter);

        // 让recycleview的item居中的方法
//        LinearSnapHelper mLinearySnapHelper = new LinearSnapHelper();
//        mLinearySnapHelper.attachToRecyclerView(mRecyclerView);
        // 处理第一个和最后一个居中问题
        mRecyclerView.addItemDecoration(new RecyclerItemCenterDecoration());
        PagerSnapHelper pagerSnapHelper=new PagerSnapHelper();
        pagerSnapHelper.attachToRecyclerView(mRecyclerView);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
        mRecyclerView.setLayoutManager(linearLayoutManager);

        // 左右滑动监听
//        mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
//            @Override
//            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
//                super.onScrollStateChanged(recyclerView, newState);
//                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
//                    View viewIdle = pagerSnapHelper.findSnapView(linearLayoutManager);
//                    if (viewIdle != null) {
//                        int position = linearLayoutManager.getPosition(viewIdle);
//                        if (position != mOrderIndex) {
////                            mAdapter.getList().get(position).setSelected(true);
////                            mAdapter.getList().get(mOrderIndex).setSelected(true);
////                            mAdapter.getItem(position).setSelected(true);
////                            mAdapter.getItem(mOrderIndex).setSelected(false);
//                            mOrderIndex = position;
//                            mAdapter.notifyDataSetChanged();
//                        }
//                    }
//                }
//            }
//        });
    }

}
